# 判断 IP地址是否属于同一子网
def PanDuanMask(STR):
    LIST = list(STR.split("."))
    STRMASK = ''
    for i in LIST:
        if i != '' and 0 <= int(i) <= 255:
            # 一定要写一个正确的表达内容，不然容易出现判断错误
            STRMASK = STRMASK + '{:08b}'.format(int(i))
        else:
            return 99
    for i in range(0, len(STRMASK)):
        if STRMASK[i] == '0':
            # 如果有全 1 的掩码，则会出现没有返回值，需要在循环外面设置一个返回值,且全1和全0 是非法
            if '1' not in STRMASK[i:] and i != 0:
                return i
            else:
                return 99
    return 99

def PanDuanIP(STR):
    LIST = list(STR.split("."))
    STRMASK = ''
    for i in LIST:
        if i != '' and 0 <= int(i) <= 255:
            # 一定要写一个正确的表达内容，不然容易出现判断错误
            STRMASK = STRMASK + '{:08b}'.format(int(i))
        else:
            return '99'
    return STRMASK

def PanDuanNet(STR1, STR2, Length):
    if STR1[0: Length] == STR2[0: Length]:
        return 0
    else:
        return 2

while True:
    try:
        s1 = input()
        s2 = input()
        s3 = input()
        if PanDuanMask(s1) == 99:
            print('1')
        else:
            if PanDuanIP(s2) == '99' or PanDuanIP(s3) == '99':
                print('1')
            else:
                print(PanDuanNet(PanDuanIP(s2), PanDuanIP(s3), PanDuanMask(s1)))
    except:
        break